package cn.com.bluemoon.daps.standard.vo;

import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.handler.inter.IExcelDataModel;
import cn.afterturn.easypoi.handler.inter.IExcelModel;
import cn.com.bluemoon.daps.common.enums.StandardDataType;
import cn.com.bluemoon.daps.standard.entity.DapStandardBasic;
import cn.com.bluemoon.daps.standard.entity.DapStandardBasicDic;
import cn.com.bluemoon.daps.standard.util.GsonExclusionField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.List;

import static org.apache.commons.lang3.builder.ToStringBuilder.reflectionToString;
import static org.apache.commons.lang3.builder.ToStringStyle.MULTI_LINE_STYLE;

/**
 * 基础标准表单组合类
 *
 * 1.基础标准信息
 * 2.基础标准关联模型中的表列表数据
 * 3.增加获取标准代码数据
 * 4.各类主键id的关联信息（翻译）
 * 5.还有Excel（easy-poi）的接口信息
 *
 * @author Jarod.Kong
 * @date 2020/8/10 10:59
 */
@ApiModel(description = "基础标准表单组合类")
@Setter
@Getter
public class BasicStandardAndDicVo extends DapStandardBasic implements Serializable, IExcelModel, IExcelDataModel {
    private static final long serialVersionUID = 1L;
    /**
     * 增加获取标准代码数据
     * 针对代码类的{@link DapStandardBasic#getDataType()} eq {@link StandardDataType#代码类}
     * 的需要对内部进行校验
     */
    @TableField(exist = false)
    @GsonExclusionField
    private List<DapStandardBasicDic> dapStandardBasicDics = Lists.newArrayList();

    @ApiModelProperty("基础标准关联模型中的表列表数据")
    @GsonExclusionField
    private List<ModelTableInfo> distributions = Lists.newArrayList();

    @TableField(exist = false)
    @Excel(name = "*标准主题")
    private String topicName;

    @TableField(exist = false)
    @Excel(name = "*一级分类")
    private String firstCategoryName;

    @TableField(exist = false)
    @Excel(name = "二级分类")
    private String secondCategoryName;

    @TableField(exist = false)
    @Excel(name = "三级分类")
    private String thirdCategoryName;

    /**
     * 对应的主管部门 {@see DapSystemDepartment#getDepartName()} ()}
     */
    @TableField(exist = false)
    @Excel(name = "*归口管理部门")
    @NotBlank(message = "[归口管理部门]不可为空")
    private String departmentName;

    @TableField(exist = false)
    @Excel(name = "制定依据")
    private String referRulesContent;

    @TableField(exist = false)
    private String errorMsg;

    @TableField(exist = false)
    private int rowNum;

    public BasicStandardAndDicVo() {
    }

    public BasicStandardAndDicVo(DapStandardBasic dapStandardBasic) {
        BeanUtils.copyProperties(dapStandardBasic, this);
    }

    @Override
    public String toString() {
        return reflectionToString(this, MULTI_LINE_STYLE);
    }

    /**
     * 对应查看 基础标准中的分布信息
     * 基础标准关联模型产生的分布数据
     */
    @Data
    @GsonExclusionField
    public static class ModelTableInfo implements Serializable {
        private static final long serialVersionUID = 1L;
        @ApiModelProperty("系统id")
        private String systemId;
        @ApiModelProperty(value = "系统名称")
        private String systemName;
        @ApiModelProperty(value = "库表名称")
        private String dbTableName;
        @ApiModelProperty(value = "模型id")
        private String modelId;
        @ApiModelProperty(value = "模型名称")
        private String modelName;
        @ApiModelProperty(value = "模型表id")
        private String modelTableId;
        @ApiModelProperty(value = "字段id")
        private String modelFieldId;
        @ApiModelProperty(value = "字段名称")
        private String modelFieldName;
        @ApiModelProperty(value = "字段类型")
        private String modelFieldType;
        @ApiModelProperty("字段长度")
        private String modelFieldLength;

    }
}
